package com.example.mysaat.service_menu_manual_test;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.mysaat.R;

public class AutoPressListViewAdapter extends BaseAdapter {
    private String []itemNames = null;
    private String []itemResult = null;
    private Context context = null;

    public AutoPressListViewAdapter(Context context,String []name,String []results){
        this.itemNames = name;
        this.itemResult = results;
        this.context = context;
    }

    @Override
    public int getCount() {
        return itemNames.length;
    }

    @Override
    public Object getItem(int i) {
        return itemNames[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view==null){
            view = LayoutInflater.from(context).inflate(R.layout.auto_press_listview_item,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.name = view.findViewById(R.id.auto_press_item);
            viewHolder.result = view.findViewById(R.id.auto_press_result);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.name.setText(itemNames[i]);
        viewHolder.result.setText(itemResult[i]);

        viewHolder.result.setBackgroundColor(Color.BLUE);
        if ("Fail".equals(itemResult[i]))
            viewHolder.result.setBackgroundColor(Color.RED);

        return view;
    }


    public class ViewHolder{
        private TextView name,result;

    }
}
